using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
namespace Hannon.FeedManager.Configuration
{
    public  class SubscriptionSettings : ConfigurationElement
    {
        private static readonly ConfigurationProperty _url;
        private static readonly ConfigurationProperty _title;
        private static readonly ConfigurationProperty _name;
        private static readonly ConfigurationProperty _description;
        private static readonly ConfigurationProperty _lastBuildDate;
        private static readonly ConfigurationProperty _tags;
        private static readonly ConfigurationProperty _feeds;
        private static readonly ConfigurationProperty _authentication;
        private static readonly ConfigurationProperty _feedType;
        private static readonly ConfigurationProperty _alertSettings;
        private static readonly ConfigurationProperty _syncSettings;
        private static readonly ConfigurationProperty _imageLink;
        private static readonly ConfigurationProperty _webSiteLink;
        private static readonly ConfigurationProperty _lastException;
        private static ConfigurationPropertyCollection _properties;
        
        static SubscriptionSettings()
        {
            SubscriptionSettings._url = new ConfigurationProperty("url", typeof(string), null, null, null, ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
            SubscriptionSettings._title = new ConfigurationProperty("title", typeof(string), "", ConfigurationPropertyOptions.IsRequired);
            SubscriptionSettings._name = new ConfigurationProperty("name", typeof(string), "", ConfigurationPropertyOptions.None);
            SubscriptionSettings._tags = new ConfigurationProperty("tags", typeof(string), "", ConfigurationPropertyOptions.None);
            SubscriptionSettings._description = new ConfigurationProperty("description", typeof(string), "", ConfigurationPropertyOptions.None);
            SubscriptionSettings._lastBuildDate = new ConfigurationProperty("lastBuildDate", typeof(string), "", ConfigurationPropertyOptions.None);            
            //SubscriptionSettings._feeds = new ConfigurationProperty("feeds", typeof(FeedSettingsCollection));
            //SubscriptionSettings._alertSettings = new ConfigurationProperty("alertSettings", typeof(SubscriptionAlertSettings));
            //SubscriptionSettings._syncSettings = new ConfigurationProperty("syncSettings", typeof(SubscriptionSyncSettings));
            //SubscriptionSettings._authentication = new ConfigurationProperty("authentication", typeof(SubscriptionAuthenticationSettings));
            SubscriptionSettings._feedType = new ConfigurationProperty("feedType", typeof(FeedFormat), FeedFormat.Unknown);
            SubscriptionSettings._imageLink = new ConfigurationProperty("imageLink", typeof(Uri), "", ConfigurationPropertyOptions.None);
            SubscriptionSettings._webSiteLink = new ConfigurationProperty("webSiteLink", typeof(Uri), "", ConfigurationPropertyOptions.None);
            //SubscriptionSettings._lastException = new ConfigurationProperty("lastException", typeof(SyncException));

            SubscriptionSettings._properties = new ConfigurationPropertyCollection();
            SubscriptionSettings._properties.Add(SubscriptionSettings._url);
            SubscriptionSettings._properties.Add(SubscriptionSettings._title);
            SubscriptionSettings._properties.Add(SubscriptionSettings._name);
            SubscriptionSettings._properties.Add(SubscriptionSettings._tags);
            SubscriptionSettings._properties.Add(SubscriptionSettings._description);
            SubscriptionSettings._properties.Add(SubscriptionSettings._lastBuildDate);
            SubscriptionSettings._properties.Add(SubscriptionSettings._feeds);
            SubscriptionSettings._properties.Add(SubscriptionSettings._alertSettings);
            SubscriptionSettings._properties.Add(SubscriptionSettings._syncSettings);
            SubscriptionSettings._properties.Add(SubscriptionSettings._authentication);
            SubscriptionSettings._properties.Add(SubscriptionSettings._feedType);
            SubscriptionSettings._properties.Add(SubscriptionSettings._imageLink);
            SubscriptionSettings._properties.Add(SubscriptionSettings._webSiteLink);
            SubscriptionSettings._properties.Add(SubscriptionSettings._lastException);
        }
        public SubscriptionSettings() {
            
        }
        public SubscriptionSettings(string url, string title, string description)
        {
            this.Url = url;
            this.Description = description;
            this.Title = title;
        }
 

        [ConfigurationProperty("url", Options = ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired, DefaultValue = "")]
        public String Url
        {
            get
            {
                return (string)base[SubscriptionSettings._url];
            }
            set
            {
                base[SubscriptionSettings._url] = value;
            }
        }

        [ConfigurationProperty("description", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public string Description
        {
            get
            {
                return (string)base[SubscriptionSettings._description];
            }
            set
            {
                base[SubscriptionSettings._description] = value;
            }
        }
        [ConfigurationProperty("title", Options = ConfigurationPropertyOptions.IsRequired, DefaultValue = "")]
        public string Title
        {
            get
            {
                return (string)base[SubscriptionSettings._title];
            }
            set
            {
                base[SubscriptionSettings._title] = value;
            }
        }
        [ConfigurationProperty("name", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public string Name
        {
            get
            {
                return (string)base[SubscriptionSettings._name];
            }
            set
            {
                base[SubscriptionSettings._name] = value;
            }
        }
        [ConfigurationProperty("tags", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public string Tags
        {
            get
            {
                return (string)base[SubscriptionSettings._tags];
            }
            set
            {
                base[SubscriptionSettings._tags] = value;
            }
        }
        [ConfigurationProperty("imageLink", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public Uri ImageLink
        {
            get
            {
                return (Uri)base[SubscriptionSettings._imageLink];
            }
            set
            {
                base[SubscriptionSettings._imageLink] = value;
            }
        }
        [ConfigurationProperty("webSiteLink", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public Uri WebSiteLink
        {
            get
            {
                return (Uri)base[SubscriptionSettings._webSiteLink];
            }
            set
            {
                base[SubscriptionSettings._webSiteLink] = value;
            }
        }
        //[ConfigurationProperty("lastException", Options = ConfigurationPropertyOptions.None, IsRequired= false)]
        //public SyncException LastException
        //{
        //    get
        //    {
        //        return (SyncException)base[SubscriptionSettings._lastException];
        //    }
        //    set
        //    {
        //        base[SubscriptionSettings._lastException] = value;
        //    }
        //}
        [ConfigurationProperty("lastBuildDate", Options = ConfigurationPropertyOptions.None, DefaultValue = "")]
        public string LastBuildDate
        {
            get
            {
                return (string)base[SubscriptionSettings._lastBuildDate];
            }
            set
            {
                base[SubscriptionSettings._lastBuildDate] = value;
            }
        }
        //[ConfigurationProperty("feeds", IsDefaultCollection = false)]
        //public FeedSettingsCollection Feeds
        //{
        //    get
        //    {
        //        return (FeedSettingsCollection)base[SubscriptionSettings._feeds];
        //    }
        //    set
        //    {
        //        base[SubscriptionSettings._feeds] = value;
        //    }
        //}
        //[ConfigurationProperty("authentication", IsDefaultCollection = false)]
        //public  SubscriptionAuthenticationSettings Authentication
        //{
        //    get
        //    {
        //        return (SubscriptionAuthenticationSettings)base[SubscriptionSettings._authentication];
        //    }
        //    set
        //    {
        //        base[SubscriptionSettings._authentication] = value;
        //    }
        //}
        [ConfigurationProperty("feedType", Options = ConfigurationPropertyOptions.IsRequired, DefaultValue = SubscriptionSettings.FeedFormat.Unknown)]
        public FeedFormat FeedType
        {
            get
            {
                return (FeedFormat)base[SubscriptionSettings._feedType];
            }
            set
            {
                base[SubscriptionSettings._feedType] = value;
            }
        }
        public enum FeedFormat { RSS, Atom, Unknown }

        //[ConfigurationProperty("syncSettings", IsDefaultCollection = false)]
        //public SubscriptionSyncSettings SyncSettings
        //{
        //    get
        //    {
        //        return (SubscriptionSyncSettings)base[SubscriptionSettings._syncSettings];
        //    }
        //    set
        //    {
        //        base[SubscriptionSettings._syncSettings] = value;                
        //    }
        //}
        //[ConfigurationProperty("alertSettings", IsDefaultCollection = false)]
        //public SubscriptionAlertSettings AlertSettings
        //{
        //    get
        //    {
        //        return (SubscriptionAlertSettings)base[SubscriptionSettings._alertSettings];
        //    }
        //    set
        //    {
        //        base[SubscriptionSettings._alertSettings] = value;
        //    }
        //}
    }
}